<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
<%@ include file="/jsp/common/common.jsp"%>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
    href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/Loading.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript" src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>      
        <script>
        
        
        
            var map = {};
            function initList(listDisplayEId) {
                $('#' + listDisplayEId).datagrid(
                        {
                            nowrap : false,
                            striped : true,
                            collapsible : true,
                            remoteSort : true,
                            notSelectByRow : false,
                            /* frozenColumns : [ [ {
                                field : 'ids',
                                checkbox : true
                            } ] ], */
                            onDblClickRow: function (rowIndex, rowData) {  
                                $('#listDisplay').datagrid('beginEdit', rowIndex);
                            },
                            toolbar : [],
                            onLoadError:function(){
                                $.messager.alert('错误','获取数据失败，请与管理员联系！','error');
                            }
                        });
            };
            $(document).ready(function() {
                initList('listDisplay');
            });
          
            function searchInfo(){
                if($('#materType').combobox('getValue') ==''){
                    $('#listDisplay').datagrid('load', {
                        materType : 0,
                        materName : $('#materName').val()
                    }); 
                }else{
                    $('#listDisplay').datagrid('load', {
                        materType : $('#materType').combobox('getValue'),
                        materName : $('#materName').val()
                    });  
                }
             }
         
         //添加信息按钮响应函数
        function addFood(){
             $('#AddFoodForm').form('submit',
            {
                url:'<c:url value='/food/addFood.do'/>', //查询提交路径
                onSubmit:function()//提交按钮相应函数
                {
                    var listDisplayEId = "listDisplay";
                    var rows = $('#'+listDisplayEId).datagrid('getSelections');    
                    for(var i=0; i<rows.length; i++){
                        var rowIndex=$('#'+listDisplayEId).datagrid('getRowIndex',rows[i]['materId']);
                        $('#listDisplay').datagrid('endEdit', rowIndex);
                    }
                    var row = $('#'+listDisplayEId).datagrid('getSelections');    
                    if(row.length == 0){
                        $.messager.alert("提示", "请选择一条记录操作！", 'info');
                        return false; 
                    }else{
                        var userList = new Array(); 
                        var jsonFater;
                        for (var i = 0 ; i < row.length;i++){
                            if ( row[i]['materWeight'] == "" || !isNumberAndNoZero(row[i]['materWeight'])  ){
                                alert("材料"+row[i]['materId']+"重量请填写数字！");
                                return false;
                            }
                            var  jsonSun = "{materId:'"+row[i]['materId']+"',materWeight:'"+row[i]['materWeight']+"'}";
                            userList.push(jsonSun);
                        }
                        jsonFater = JSON.stringify(userList);
                        document.getElementsByName("fooddategridList")[0].value = jsonFater;
                        return $('#AddFoodForm').form('validate');
                    }
                    
                },
                success:function(data){
                    data = eval('(' + data + ')');
                    var msgsuccess = data.success+"";
                       /* if(msgsuccess == "true"){
                           alert(1);
                           $.messager.alert("提示", "修改成功！", 'info');
                           window.close();
                       }else{
                           $.messager.alert("提示", data.msg, 'warning');
                       } */
                       
                    if (data.success) {
                        $.messager.alert('系统提示', '保存成功', 'info', function(){
                            window.opener.window.tea();
                            window.close();
                        });
                    } else {
                        var message = "";
                           if(data.msg == "0003"){
                               message = "此种菜品名称已经录入！";
                           }
                           $.messager.alert("提示", message, 'warning');
                    }
                },
                error:function(){
                    $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                    return;
                }
            });
             
        }

         
        $(function() {        
              // 下拉框选择控件，下拉框的内容是动态查询数据库信息  
              $('#foodType').combobox({   
                      url:'<c:url value='/food/pulldownFoodType.do'/>',   
                      editable:false, //不可编辑状态  
                      cache: false,  
                      panelHeight: '150',  
                      valueField:'foodType',     
                      textField:'foodTypename',  
              });      
                
              // 下拉框选择控件，下拉框的内容是动态查询数据库信息  
              $('#foodType1').combobox({   
                      url:'<c:url value='/food/pulldownFoodType1.do'/>',   
                      editable:false, //不可编辑状态  
                      cache: false,  
                      panelHeight: '150',  
                      valueField:'foodType1',     
                      textField:'foodTypename1',  
              });      
              
              // 下拉框选择控件，下拉框的内容是动态查询数据库信息  
              $('#materType').combobox({   
                  data:[{"materType":"0","ordStateName":"全部"},{"materType":"1","ordStateName":"牛肉类"},{"materType":"2","ordStateName":"海鲜类 "},{"materType":"3","ordStateName":"水发类"},{"materType":"4","ordStateName":"猪肉类"},{"materType":"5","ordStateName":"浇头"},{"materType":"6","ordStateName":"鸭肉类"},{"materType":"7","ordStateName":"鸡肉类"},{"materType":"8","ordStateName":"鸡蛋类"},{"materType":"9","ordStateName":"鹌鹑类"},{"materType":"10","ordStateName":"河鲜类"},{"materType":"11","ordStateName":"豆制品类"},{"materType":"12","ordStateName":"根茎类"},{"materType":"13","ordStateName":"鸭蛋类"},{"materType":"14","ordStateName":"干货类"},{"materType":"15","ordStateName":"绿叶菜"},{"materType":"16","ordStateName":"瓜果类"},{"materType":"17","ordStateName":"叶菜"},{"materType":"18","ordStateName":"其他类"},{"materType":"19","ordStateName":"猪骨类"},{"materType":"20","ordStateName":"蛋类"},{"materType":"21","ordStateName":"酸辣"},{"materType":"22","ordStateName":"咸菜类"},{"materType":"23","ordStateName":"鱼头类"},{"materType":"24","ordStateName":"猪血"}],   
                  editable:false, //不可编辑状态  
                  cache: false,  
                  valueField:'materType',     
                  textField:'ordStateName',  
              }); 
        }); 
        </script>
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
    <table width="90%" align="center">
      <tr>
        <td>
          <div style="height: auto; background: #fafafa; padding: 5px;" class="easyui-panel" title="添加菜品信息" iconCls="icon-save" 
              collapsible="true" minimizable="false" maximizable="false" closable="false">
               <table>
               <tr><td>
               <form id="AddFoodForm" name="AddFoodForm" method="post">
               <table>
                  <tr>
                      <td>菜品名:</td>
                    <td>
                        <input class="easyui-validatebox" type="text" name="foodName" data-options="required:true" />
                     </td>
                  </tr>
                  <tr>
                      <td>品别:</td>
                      <td>
                          <input class="easyui-combobox"   name="foodType" id="foodType" data-options="required:true" />
                       </td>
                  </tr>
                  <tr>
                      <td>类别:</td>
                      <td>
                          <input class="easyui-combobox"   name="foodType1" id="foodType1" data-options="required:true" />
                       </td>
                  </tr>
                  <tr>
                      <td>主料大全:</td>
                      <td>
                          <input class="easyui-validatebox" type="text" name="foodMtype" data-options="required:true" />
                       </td>
                  </tr>
                  <tr>
                      <td>主料半成品名称:</td>
                      <td>
                          <input class="easyui-validatebox" type="text" name="foodMname" data-options="required:true" />
                       </td>
                  </tr>
                 
                  
                  <tr>
                    <td>
                        <input class="easyui-validatebox" type="hidden" name="fooddategridList" data-options="required:false" />
                     </td>
                  </tr>
                  
                  </table>
                  </td></tr>
                  </form>
                   
                   
                   <tr style="height: 12px;"></tr>
                   
                   <tr>
                       <td colspan="2">
                           <div style="height: auto; background: #fafafa; padding: 5px;" class="easyui-panel" title="搜索" iconCls="icon-save" 
                                    collapsible="true" minimizable="false" maximizable="false" closable="false">
                               <form id="searchForm" name="searchForm" method="post"
                                    action="userlist.txt"
                                    onsubmit="return searchDGData(this.id,'listDisplay');">
                                   <div>
                                       <table cellpadding="5">
                                           <tr>
                                               <td>材料名：</td>
                                               <td><input class="easyui-validatebox" id="materName" editable="true" name="materName"></input></td>
                                               <td>类别：</td>
                                               <td><input class="easyui-combobox" id="materType" editable="false" name="materType"></input></td>
                                               <td><input type="button" onclick="searchInfo()" value="查询"></td>
                                           </tr>
                                       </table>
                                   </div>
                               </form>
                          </div>
                       </td>
                   </tr>
            </table>
            <table id="listDisplay" title="材料列表" 
                      iconCls="icon-list" singleSelect="false" idField="materId"
                      url="<c:url value="/mater/findEditorMater.do"/>" loadMsg="请稍候......"
                      pagination="true" pageSize="20"
                      pageList="[10,20,20,20,50]" sortName="materId"
                      rownumbers="true" sortOrder="asc">
                    <thead>
                    <tr>
                        <th field="materRole" width="25" align="center" checkbox="true">
                        </th> 
                        <th field="materId" width="80"  sortable="true" >材料ID
                        </th>    
                        <th field="materName" width="80"  sortable="true" >材料名
                        </th>        
                        <th field="materType" width="60"  sortable="true" formatter="formatFoodType1">种类
                        </th>    
                        <th field="materDescribe" width="150" sortable="true" >描述
                        </th>    
                        <th field="materWeight" width="150"  sortable="true" editor="text">重量(克)
                        </th>
                     </tr>
                     </thead>
            </table>
                <a href="#" class="easyui-linkbutton" onclick="addFood()">添加</a>
          </div>
        </td>
      </tr>
    </table>
  </body>
</html>